<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<<<<<<< HEAD
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
=======
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>

>>>>>>> branch 'master' of https://gitee.com/cjt1997/gameTransactionPlatform.git
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<%
	String path = request.getContextPath();
	String basePath = request.getScheme() + "://"
			+ request.getServerName() + ":" + request.getServerPort()
			+ path + "/";
%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<base href="<%=basePath%>">
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
<script src="https://code.jquery.com/jquery-3.1.1.min.js"></script>
<script type="text/javascript" src="js/bootstrap.min.js"></script>
<script type="text/javascript" src="js/jquery-1.8.3.min.js"></script>
<script type="text/javascript" src="js/vue/vue.js"></script>
<script type="text/javascript"> src="layui/layui.js"</script>
<script type="text/javascript" src="js/sweetalert/sweetalert2.min.js"></script>
<link rel="stylesheet" type="text/css" href="css/sweetalert2.min.css" />
<link rel="stylesheet" type="text/css" href="css/bootstrap.min.css" />
<link rel="stylesheet" type="text/css" href="layui/css/layui.css" />
<link rel="stylesheet" href="//at.alicdn.com/t/font_521009_eavzedzuywnah5mi.css">

<style type="text/css">
body{
	background-color:#101822;
}
td{
	text-align:center;
	font-size:22px;
	}
#header{
	background-color:#101822;
	width:80%;
	height:100px;
	margin:auto;
}
li{
	float:left;
	list-style:none;
	padding:0px;
	margin:0px;
}
a:hover,a{
	color:white;
	font-size:30px;
	text-decoration:none;
	display:block;
	padding:15px 70px;
}
img{
	margin:auto;
}
</style>
</head>

<script type="text/javascript">
function seeOrder(){
	//alert("进入订单页面");
	window.location="Order.jsp";
}
</script>

<script type="text/javascript">
function closeMoTaiKuang(){
	window.location="Goods.jsp";
}
</script>

<body>

<div id="header">
	<ul>
		<li><a href="#">首页</a></li>
		<li><a href="#">注册</a></li>
		<li><a href="#">登录</a></li>
		<li><a href="#">讨论区</a></li>
		<li><a href="#">积分商城</a></li>
		<li><a href="#">帮助信息</a></li>
	</ul>
</div>
<!-- ====================================================================================================================== -->
<div id="myCarousel" class="carousel slide">
	   
	<!-- 轮播（Carousel）项目 -->
	<div class="carousel-inner">
		<div class="item active">
			<img src="images/人马.jpg" alt="First slide">
		</div>
		<div class="item">
			<img src="images/锤石.jpg" alt="Second slide">
		</div>
		<div class="item">
			<img src="images/剑姬.jpg" alt="Third slide">
		</div>
		<div class="item">
			<img src="images/风女.jpg" alt="Third slide">
		</div>
		<div class="item">
			<img src="images/金克丝.jpg" alt="Third slide">
		</div>
		<div class="item">
			<img src="images/琴女.jpg" alt="Third slide">
		</div>
		<div class="item">
			<img src="images/赵信.jpg" alt="Third slide">
		</div>
	</div>
	<!-- 轮播（Carousel）导航 -->
	<a class="carousel-control left" href="#myCarousel" 
	   data-slide="prev">&lsaquo;</a>
	<a class="carousel-control right" href="#myCarousel" 
	   data-slide="next">&rsaquo;</a>
</div> 
<!-- ======================================================================================================================= -->

<div style="width:80%;margin:auto" id="app">
<table class="table">
	<tr>
		<td class="layui-bg-red">商品名称</td>
		<td class="layui-bg-orange">商品价格</td>
		<td class="layui-bg-green">商品图片</td>
		<td class="layui-bg-cyan">商品数量</td>
		<td class="layui-bg-blue">商品备注</td>
		<td class="layui-bg-black">上架时间</td>
		<td class="layui-bg-red">操作</td>
	</tr>
		<tr v-for="li in list">
			<td class="layui-bg-red">{{li.gname}}</td>
			<td class="layui-bg-orange">{{li.gprice}}</td>
			<td class="layui-bg-green"><img alt="图片暂时无法加载" v-bind:src="li.gphoto" style="height:100px"></td>
			<td class="layui-bg-cyan">{{li.gsum}}</td>
			<td class="layui-bg-blue">{{li.gdetail}}</td>
			<td class="layui-bg-black">{{li.gtime}}</td>
			<td class="layui-bg-red"><input type="button" value="加入订单" class="layui-btn layui-btn-danger"
			 v-on:click="addOrder(li.g_gz_gc_id,li.gprice,li.gsum,li.gtime,li.u_Id,li.gphoto,li.gdetail,li.goodsAllClass,li.gid)"
			  data-toggle="modal" data-target="#myModal"><i class="iconfont icon-add"></i></td>
		</tr>
</table>
</div>

<!-- 模态框按钮 -->
<!-- <button class="btn btn-primary btn-lg" data-toggle="modal" data-target="#myModal">
  Launch demo modal
</button> -->

<!-- Modal 模态框 -->
<div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
  <div class="modal-dialog" id="ao">
    <div class="modal-content">
      <div class="modal-header">
        <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
        <h3 class="modal-title layui-bg-green" id="myModalLabel" style="text-align:center">添加订单成功!</h3>
      </div>
      <div class="modal-body">
        <table class="table">
        	<tr>
        		<td class="layui-bg-black">商品价格</td>
        		<td class="layui-bg-red">商品数量</td>
        		<td class="layui-bg-orange">商品图片</td>
        		<td class="layui-bg-green">上架时间</td>
        		<td class="layui-bg-blue">备注</td>
        	</tr>
        	<tr>
        		<td id="td01" class="layui-bg-black"></td>
        		<td id="td02" class="layui-bg-red"></td>
        		<td class="layui-bg-orange"><img alt="图片暂时无法加载" style="height:100px" id="td03"></td>
        		<td id="td04" class="layui-bg-green"></td>
        		<td id="td05" class="layui-bg-blue"></td>
        	</tr>
        </table>
      </div>
      <div class="modal-footer">
        <button type="button" class="layui-btn layui-btn-normal" data-dismiss="modal" onclick="closeMoTaiKuang()">关闭</button>
        <button type="button" class="layui-btn layui-btn-normal" data-dismiss="modal" onclick="seeOrder()">进入订单页面查询</button>
      </div>
    </div>
  </div>
</div>

</body>
<!-- vue展示商品 -->
<script type="text/javascript">

//jQuery获取地址栏参数
function GetQueryString(name)
{
     var reg = new RegExp("(^|&)"+ name +"=([^&]*)(&|$)");
     var r = window.location.search.substr(1).match(reg);
     if(r!=null)return  unescape(r[2]); return null;
}


$(function(){
	var gid2=GetQueryString("gid");
	$.ajax({
		url:'listGoods',
<<<<<<< HEAD
		type:'post',

=======
		type:'post',
>>>>>>> branch 'master' of https://gitee.com/cjt1997/gameTransactionPlatform.git
		data:{"gid":gid2},
<<<<<<< HEAD

=======
>>>>>>> branch 'master' of https://gitee.com/cjt1997/gameTransactionPlatform.git
		dataType:'json',
		async:true,
		success:function(result){
			//console.log("你好listGoods");
			vue.list=result;
		}
	});
});
var vue=new Vue({
	el:'#app',
	data:{
		list:""
	},
	methods:{
		addOrder:function(g_gz_gc_id,gprice,gsum,gtime,u_Id,gphoto,gdetail,goodsAllClass,gid){
			/* console.log(gtime);
			console.log(u_Id);
			console.log(gdetail); */
			if(gsum>0){
				gsum=1;
				$("#td01").html(gprice);
				$("#td02").html(gsum);
				$("#td03").attr("src",gphoto);
				$("#td04").html(gtime);
				$("#td05").html(gdetail);
				//加入订单时扣除用户余额,判断用户余额是否可以购买该商品,可以的话修改购买过后的用户账户余额,不可以提示用户余额不足,刷新当前页
				$.ajax({
					url:'queryUser',
					data:{"u_Id":u_Id,"gprice":gprice},
					dataType:'json',
					type:'post',
					success:function(result){
						if(result.money>0){
							sweetAlert("购买成功!","您的账户余额还有"+result.money+"元","success");
							//添加指定商品到订单
							$.ajax({
								url:'addBuyGoodsByGoods',
								data:{"g_gz_gc_id":g_gz_gc_id,"gprice":gprice,"gsum":gsum,"gtime":gtime,"u_Id":u_Id,"gphoto":gphoto,"gdetail":gdetail,"goodsAllClass":goodsAllClass},
								dataType:'json',
								type:'post',
								success:function(result){
									//console.log(gprice);
								}
							});
							//加入商品库存数量减1
							$.ajax({
								url:'updateGoodsCount',
								data:{"gid":gid},
								dataType:'json',
								type:'post',
								success:function(result){
									//console.log(result.gid);
								}
							});
							$.ajax({
								url:'increaseUserIntegral',
								data:{"u_Id":u_Id,"gprice":gprice},
								type:'post',
								dataType:'json',
								success:function(result){
									//console.log("用户积分======"+result.integral);
								}
							});
						}else{
							$("#ao").hide();
							swal({
								  title: '警告!警告!',
								  text: result.error,
								  type: 'error',
								  showCancelButton: false,
								  confirmButtonColor: '#3085d6',
								  cancelButtonColor: '#d33',
								  confirmButtonText: '确定',
								}).then(function(isConfirm) {
								  if (isConfirm) {
								  window.location.reload();
								  }
								})
						}
					}
				});
			}else{
				//alert("gid="+gid);
				$("#ao").hide();
				 $.ajax({
					url:'deleteGoods',
					data:{"gid":gid},
					dataType:'json',
					type:'post',
					async:true,
					success:function(result){
						
					}
				});  
				swal({
					  title: '警告!警告!',
					  text: "商品库存不足!",
					  type: 'error',
					  showCancelButton: false,
					  confirmButtonColor: '#3085d6',
					  cancelButtonColor: '#d33',
					  confirmButtonText: '确定',
					}).then(function(isConfirm) {
					  if (isConfirm) {
					  window.location.reload();
					  }
					})
			}
			
		}
	}
});
</script>

</html>